import { BasicColumn, FormSchema } from '/@/components/Table';
import { defaultRule, rules } from '@/utils/common/validator';
import { userRemarkFormItem, userStatusFormItem, userStatusFormItemSelect } from '@/settings/ShareFormItem';
import { userRemarksColumn, userStatusColumn } from '@/settings/ShareTableColumns';
import { apiPostUnitCheckCodeUniqueQuery } from '@/api/http/system/auxiliary/unit/unit.api';

export const useUnitUpdateSchemaForm = (): FormSchema[] => {
  return [
    { field: 'name', label: '单位名称', component: 'Input', rules: defaultRule() },
    { field: 'code', label: '单位编码', component: 'Input', dynamicRules: ({ model, schema }) => rules.uniqueFieldValidation(apiPostUnitCheckCodeUniqueQuery, 'id', schema, model) },

    userStatusFormItem(),
    userRemarkFormItem(),
    { field: 'id', label: '商品单位编号', component: 'Input', show: false },
  ];
};

export const useUnitListColumns = (): BasicColumn[] => {
  return [{ title: '商品单位编码', dataIndex: 'code' }, { title: '商品单位名称', dataIndex: 'name' }, userStatusColumn(), userRemarksColumn()];
};

export const useUnitListSearchForm = (): FormSchema[] => {
  return [{ field: 'name', label: '名称', component: 'Input' }, { field: 'code', label: '编码', component: 'Input' }, userStatusFormItemSelect()];
};
